import { http } from '@/utils/http'
import type { AddressParams, AddressResult, AddressItem } from '@/types/address'

/**
 * 添加收货地址
 * @param {AddressParams} data 地址参数
 */
export const addAddressAPI = (data: AddressParams) => {
  return http<AddressResult>({
    url: '/member/address',
    method: 'POST',
    data,
  })
}

/**
 * 修改收货地址
 * @param { string } id 收货地址id
 * @param { AddressParams } data 地址参数
 */
export const updateAddressAPI = (id: string, data: AddressParams) => {
  return http<AddressResult>({
    url: `/member/address/${id}`,
    method: 'PUT',
    data,
  })
}

/**
 * 删除收货地址
 * @param { string } id 收货地址id
 */
export const deleteAddressAPI = (id: string) => {
  return http<AddressResult>({
    url: `/member/address/${id}`,
    method: 'DELETE',
  })
}

/**
 * 获取收货地址详情
 * @param { string } id 收货地址id
 */
export const getAddressDetailAPI = (id: string) => {
  return http<AddressItem>({
    url: `/member/address/${id}`,
    method: 'GET',
  })
}
/**获取收货地址列表 */
export const getAddressListAPI = () => {
  return http<AddressItem[]>({
    url: '/member/address',
    method: 'GET',
  })
}
